package com.hk.service.impl;

import com.hk.dao.NewsDao;
import com.hk.model.News;
import com.hk.model.NewsType;
import com.hk.service.INewsService;
import com.hk.service.INewsTypeService;

import java.util.List;

/**
 * @Author: KangWang
 * Date: 2021/5/20 10:50
 * State：新闻业务逻辑层
 */
public class NewsServiceImpl implements INewsService {

    @Override
    public List<News> findAllNews() {
        NewsDao newsDao = new NewsDao();
        List<News> newsList = newsDao.findAllNews();
//        获取新闻类型
        INewsTypeService iNewsTypeService = new NewsTypeServiceImpl();
        List<NewsType> newsTypes = iNewsTypeService.findAllNewsType();
        if (newsList == null && newsList.isEmpty()) {
            System.out.println("暂无新闻");
            return null;
        }
        //            判断新闻属于哪个新闻类型
        for (NewsType newsType : newsTypes) {
            for (News news : newsList) {
                if (newsType.getTypeId() == news.getTypeId()) {
                    news.setNewsType(newsType);
                }
            }
        }
        return newsList;
    }


}
